package svc

import (
	"suci-go-zero/internal/config"
	"suci-go-zero/internal/model"

	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

type ServiceContext struct {
	Config   config.Config
	RedisObj *redis.Redis
	Models   *models
}
type models struct {
	Session sqlx.Session
	MenuApi model.AdminMenuApiModel
	Menu    model.AdminMenuModel
	Role    model.AdminRoleModel
	User    model.AdminUserModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlconn := sqlx.NewMysql(c.DB.DataSource)
	return &ServiceContext{
		Config:   c,
		RedisObj: c.RedisConf.NewRedis(),
		Models: &models{
			Session: sqlconn,
			MenuApi: model.NewAdminMenuApiModel(sqlconn, c.Cache),
			Menu:    model.NewAdminMenuModel(sqlconn, c.Cache),
			Role:    model.NewAdminRoleModel(sqlconn, c.Cache),
			User:    model.NewAdminUserModel(sqlconn, c.Cache),
		},
	}
}
